﻿#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
using System;

namespace AbstractClass.NPerf
{
    /// <summary>
    /// Represents a failed test result.
    /// </summary>
    public class FailedResult
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FailedResult"/> class.
        /// </summary>
        public FailedResult()
        {
            FailedUnit = null;
            ExceptionType = null;
            Message = null;
            Source = null;
            FullMessage = null;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FailedResult"/> class.
        /// </summary>
        /// <param name="testUnit">The test unit which has failed.</param>
        /// <param name="ex">The exception causing the failure.</param>
        public FailedResult(TestUnit testUnit, Exception ex)
        {
            if (testUnit == null)
                throw new ArgumentNullException("testUnit");
            if (ex == null)
                throw new ArgumentNullException("ex");

            Exception iex = ex;

            if (ex.InnerException != null)
                iex = ex.InnerException;
            FailedUnit = testUnit;
            ExceptionType = iex.GetType().Name;
            Message = iex.Message;
            Source = iex.Source;
            FullMessage = iex.ToString();
        }

        /// <summary>
        /// Gets or sets the failed test unit.
        /// </summary>
        /// <value>The failed unit.</value>
        public TestUnit FailedUnit { get; set; }

        /// <summary>
        /// Gets or sets the type of the exception.
        /// </summary>
        /// <value>The type of the exception.</value>
        public string ExceptionType { get; set; }

        /// <summary>
        /// Gets or sets the error message.
        /// </summary>
        /// <value>The error message.</value>
        public string Message { get; set; }

        /// <summary>
        /// Gets or sets the source of the exception.
        /// </summary>
        /// <value>The source of the exception.</value>
        public string Source { get; set; }

        /// <summary>
        /// Gets or sets the full message of the exception.
        /// </summary>
        /// <value>The full message of the exception.</value>
        public string FullMessage { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the reason of the failure is an assertion failure.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if the test unit has failed due to <see cref="Framework.AssertionException"/>; otherwise, <c>false</c>.
        /// </value>
        public bool IsAssertionFailed { get; set; }
    }
}